package com.flyox.game.militarychess.client.services;

import java.awt.Color;
import java.util.Hashtable;

import com.flyox.game.militarychess.bean.ChessDesk;
import com.flyox.game.militarychess.bean.ChessMan;
import com.flyox.game.militarychess.bean.Player;
import com.flyox.game.militarychess.bean.ChessDesk.DESK_STATE;
import com.flyox.game.militarychess.bean.ChessSeat.SEAT_NAME;
import com.flyox.game.militarychess.client.services.data.ClientInfo;

public class DataService {
	ClientInfo clientInfo = new ClientInfo();

	public ChessDesk getChessDesk() {
		return clientInfo.getChessDesk();
	}

	public void setChessDesk(ChessDesk chessDesk) {
		clientInfo.setChessDesk(chessDesk);
	}
	//
	public Player getPlayer() {
		return clientInfo.getPlayer();
	}

	public void setPlayer(Player player) {
		clientInfo.setPlayer(player);
	}

	public String getPlayerID() {
		if (clientInfo.getPlayer() != null) {
			return clientInfo.getPlayer().getId();
		} else {
			return "";
		}
	}
	//
	public Hashtable<Integer, ChessDesk> getDesks() {
		return clientInfo.getDesks();
	}

	public void setDesks(Hashtable<Integer, ChessDesk> desks) {
		clientInfo.setDesks(desks);
	}

	public synchronized SEAT_NAME getOnTurn() {
		if (clientInfo.getChessDesk() != null) {
			return clientInfo.getChessDesk().getOnTurn();
		} else {
			return SEAT_NAME.S1;
		}
	}
	public DESK_STATE getDeskStates() {
		if (clientInfo.getChessDesk() != null) {
			return clientInfo.getChessDesk().getDeskStates();
		} else {
			return DESK_STATE.EMPTY;
		}
	}
	//
	public String getServerIP() {
		return clientInfo.getServerIP();
	}

	public void setServerIP(String serverIP) {
		clientInfo.setServerIP(serverIP);
	}

	public int getServerPort() {
		return clientInfo.getServerPort();
	}

	public void setServerPort(int serverPort) {
		clientInfo.setServerPort(serverPort);
	}
	/**
	 * 
	 * @param changVisualAngle
	 * @return
	 */
	public ChessMan[][] getLayout() {
		ChessMan[][] layout=clientInfo.getLayout();
//		SEAT_NAME sn=getPlayer().getSeatName();
//		if(sn.equals(SEAT_NAME.S1)||sn.equals(SEAT_NAME.S2)||sn.equals(SEAT_NAME.S3)||sn.equals(SEAT_NAME.S4)){
//			new CommonLayoutService().changeVisualAngle(layout);
//		}
		return layout;
	}

//	public ChessMan[][] getLayout(boolean changVisualAngle) {
//		ChessMan[][] layout=clientInfo.getLayout();
//		SEAT_NAME sn=getPlayer().getSeatName();
//		if(changVisualAngle&&(sn.equals(SEAT_NAME.S1)||sn.equals(SEAT_NAME.S2)||sn.equals(SEAT_NAME.S3)||sn.equals(SEAT_NAME.S4))){
//			new CommonLayoutService().changeVisualAngle(layout);
//		}
//		return layout;
//	}
	public void setLayout(ChessMan[][] layout) {
		clientInfo.setLayout(layout);
	}
	//
	public Color getSeatColor(SEAT_NAME seatName){
		switch(seatName){
		case S1:
			return new Color(0x2E,0x69,0xA6);
		case S2:
			return new Color(0x31,0x8A,0x9B);
		case S3:
			return new Color(0x74,0x9D,0x04);
		case S4:
			return new Color(0x17,0x80,0x53);
		case S5:
			return new Color(0xDC,0x6D,0x00);
		case S6:
			return new Color(0xA0,0x4F,0x02);
		case S7:
			return new Color(0x90,0x44,0xA6);
		case S8:
			return new Color(0x63,0x35,0x53);
		default:
			return new Color(255,255,255);
		}
		
//		if (clientInfo.getChessDesk() != null) {
//			System.out.println("chessDesk is not null seatName="+seatName);
//			System.out.println(clientInfo.getChessDesk().getSeats().get(seatName).getSeatColor());
//			return clientInfo.getChessDesk().getSeats().get(seatName).getSeatColor();
//		}else{
//			return new Color(255,255,255);
//		}
	}
}
